﻿@{
    ViewData["Title"] = "PLC写入数据配置";
    ViewData["Mbx"] = "配置管理";
    Layout = "_Default";
}

@section css{
    <style>
        
        .fliter {
            width: 95%;
            height: 60px;
            align-items: center;
            display: flex;
            margin-bottom: 20px;
        }
        .fliter .search-btn {
            margin-left: 20px;
        }
        .fliter .input-text-eq-name{
            width: 140px;
            height: 23px;
        }
        .fliter .label-eq-code{
            margin-left: 20px;
        }
        .fliter .input-text-eq-code{
            width: 140px;
            height: 23px;
        }
        .fliter .input-text-dbcode{
            width: 100px;
            height: 23px;
        }
        .select-box{
            width: 180px;
        }
    </style>
}

@section gray{
    <div class="fliter">
    <label class="label-eq-name">设备号：</label>
    <input type="text" class="input-text-eq-code" value="" placeholder="" id="equipmentCode" name="equipmentCode">
    <label class="label-eq-code">报文写入类型：</label>
    <input type="text" class="input-text-eq-code" value="" placeholder="" id="objectType" name="objectType">
    <label class="label-eq-code">DB编号：</label>
    <input type="text" class="input-text-dbcode" value="" placeholder="" id="DBCode" name="DBCode">
    <label class="label-eq-code">连接IP：</label>
    <span class="select-box">
        <select class="select" size="1" name="ipSearch" id="ipSearch">
            <option value="0" selected>--请选择--</option>
            @foreach (var item in Model.PlcIpSearchs)
            {
                <option value="@item.PlcConnectId">@item.PlcConnectIp</option>
            }
        </select>
    </span>
    <input class="btn btn-primary radius search-btn" type="button" onclick="search()" value="&nbsp;&nbsp;搜索&nbsp;&nbsp;">
</div>
    <div>
        <span class="l">
    <a class="btn btn-primary radius" href="javascript:;" onclick="common_add('添加PLC写入DB配置','/plcwritedb/plcwritedbinfoaddoredit','700','400')">
        <i class="Hui-iconfont">&#xe600;</i> 新增
    </a>
</span>
    </div>

}




<table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>

@section javascript{
<script>
    $(function(){
        initData("", "", 0);
    });

    
    function search(){
        var equipmentCode = $("#equipmentCode").val();
        var objectType = $("#objectType").val();
        var DBCode = $("#DBCode").val();
        var ipSearch = $("#ipSearch").val();
        initData(equipmentCode,objectType, DBCode,ipSearch);
    }

    function initData(equipmentCode,objectType, DBCode,ipSearch){
        $('.table-sort').dataTable({
            bProcessing: true, //DataTables 载入数据时，是否显示‘进度’提示
            bAutoWidth: false, //自动宽度
            bSort: false, //排序功能
            paging : true, //是否分页
            bInfo: true, //页脚信息,默认为 true
            bStateSave: false, //状态保存
            sPaginationType: "full_numbers", //分页显示样式
            serverSide: true, //启用服务器分页
            //sAjaxSource: "/admin/functionlist", //服务端请求数据接口
            searching: true, //关闭 datatables 的搜索框
            destroy: true, //解决重新渲染问题
            iDisplayLength: 10, //每页显示数量
            ajax:{
                    url: "/plcwritedb/getallplcwritedbinfo",
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded",
                    async: false,
                    dataType: "json",
                    data: function(data){
                        data.equipmentCode = equipmentCode;
                        data.objectType = objectType;
                        data.DBCode = DBCode;
                        data.ipSearch = ipSearch;
                    },
                    dataFilter: function(json){
                        console.log(json);
                        return json;
                    }
               },

            aoColumns:[
                // mDataProp：绑定数据属性
                // sDefaultContent：设置默认值
                // sClass：添加 class 属性，不懂的直接去掉
                // sTtile：设置列标题
                // sWidth：设置列宽度
                // sTtile 设置的内容，会替换到 html thead 中的“标题”
                //{mDataProp:"js_Id", sClass:"text-c",  sTitle:"编号",sDefaultContent:""},
                {mDataProp:"js_Id", sClass:"text-c", sTitle:"ID",sDefaultContent:"",sWidth:"10%"},
                {mDataProp:"dbCode",  sClass:"text-c", sTitle:"DB编号",sDefaultContent:"",sWidth:"5%"},
                {mDataProp:"dbStart",  sClass:"text-c", sTitle:"DB读取起始位",sDefaultContent:"",sWidth:"5%"},
                {mDataProp:"equipmentCode",  sClass:"text-c", sTitle:"设备号",sDefaultContent:"",sWidth:"5%"},
                {mDataProp:"objectType",  sClass:"text-c", sTitle:"写入对象类型",sDefaultContent:"",sWidth:"10%"},
                {mDataProp:"plcConnectionIP",  sClass:"text-c", sTitle:"PLC连接IP",sDefaultContent:"",sWidth:"8%"},
                {mDataProp:"plcCpuTypeName",  sClass:"text-c", sTitle:"CPU类型",sDefaultContent:"",sWidth:"7%"},
                {mDataProp:"js_Id", sClass:"text-c", sTitle:"操作",sWidth:"10%",
                 mRender: function(data, type, row){
                       var html= "<a title=\"编辑\" href=\"javascript:;\" onclick=\"common_add('编辑PLC连接配置',\'/plcWritedb/plcwritedbinfoaddoredit/"+data+"','700','400')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
                       html += "<a title=\"删除\" href=\"javascript:;\" onclick=\"DelPlcWriteDBInfoAsync('"+data+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe609;</i></a>";
                          return html;
                    }
                 }
            ],
            oLanguage: { //国际化配置
                sProcessing : "正在获取数据，请稍后...",
                sLengthMenu : "显示 _MENU_ 条",
                sZeroRecords : "没有您要搜索的内容",
                sInfo : "从 _START_ 到  _END_ 条记录 总记录数为 _TOTAL_ 条",
                sInfoEmpty : "记录数为0",
                sInfoFiltered : "(全部记录数 _MAX_ 条)",
                sInfoPostFix : "",
                sSearch : "从当前数据中检索： ",
                sUrl : "",
                oPaginate: {
                    sFirst : "首页",
                    sPrevious : "上一页",
                    sNext : "下一页",
                    sLast : "尾页"
                }
            }
        });
    }
    
    function DelPlcWriteDBInfoAsync(id) {
        console.log(id);
        popupConfirm("确定删除该PLC读取DB配置吗？",0, function(){
            var data = { 'id' : id };
            SubmitFormForAjax("/plcwritedb/delplcwritedbinfo", data, function (data) {
                if (data.result) {
                    popupAlert('删除成功！',1,function(){
                        location.reload();//刷新页面
                    });
                }else{
                popupAlert('删除失败！',1,function(data){
                    layer.close(data);
                });
                }
            },true);

        });

    }

    
</script>
}

